package org.yenn.pattern.aliyun.j2ee.dataaccess;

import org.junit.Test;
import org.yenn.pattern.aliyun.j2ee.dataaccess.impl.StudentDaoImpl;
import org.yenn.pattern.aliyun.j2ee.entity.Student;

import static org.junit.Assert.*;

/**
 * @Author: yerenyun
 * @Description:步骤 4
 * 使用 StudentDao 来演示数据访问对象模式的用法。
 */
public class DataAccessObjectPatternDemo {
    /**
     * 步骤 5
     * 验证输出。
     *
     */
    @Test
    public void getAllStudents() {
        StudentDao studentDao = new StudentDaoImpl();

        //输出所有的学生
        for (Student student : studentDao.getAllStudents()) {
            System.out.println(student);
        }


        //更新学生
        Student student = studentDao.getAllStudents().get(0);
        student.setName("Michael");
        studentDao.updateStudent(student);

        //获取学生
        Student student1 = studentDao.getStudent(0);
        System.out.println(student1);

        // 删除学生
        studentDao.deleteStudent(student1);
    }
}